/**
 * @Title: PreviewPhotoActivity.java
 * @Package: com.jason.bluetooth.fingerprint.ui
 * @Descripton: TODO
 * @Author: Jason.Zhang zhangyujn1989ok@gmail.com
 * @Date: 2014年10月22日 下午9:29:16
 * @Version: V1.0
 */
package com.jason.platform.supervision.activity;

import android.os.Bundle;
import android.os.Message;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import com.hzlj.supervision.changsha.R;
import com.jason.platform.supervision.adapter.PreviewPagerAdapter;
import com.jason.platform.supervision.widght.TitleBar;

import java.util.List;

/**
 * @ClassName: PreviewPhotoActivity
 * @Description: 图片查看器
 * @Author: Jason.Zhang zhangyujn1989ok@gmail.com
 * @Date: 2014年10月22日 下午9:29:16
 */
public class PreviewPhotoActivity extends BaseActivity {
	
	private ViewPager mPreviewViewPager;
//	private DisplayImageOptions mDisplayImageOptions;
	private PreviewPagerAdapter mPreviewPagerAdapter;
	private String[] mImages;
	private List<String> list;
	private TitleBar mTitleBar;
	
	private List<String> mCacheCheckImages;

	@Override
	void handleMessage(BaseActivity activity, Message msg) {

	}

	/* (non-Javadoc)
         * @see android.app.Activity#onCreate(android.os.Bundle)
         */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.activity_preview_photo);
		super.onCreate(savedInstanceState);
		mTitleBar = (TitleBar) findViewById(R.id.title_bar);
		mTitleBar.bindActivity(this);
	}

	@Override
	protected void initWidget() {
		super.initWidget();
		init();
	}
	

	private void init(){
		list = getIntent().getStringArrayListExtra("images");
		mCacheCheckImages = getIntent().getStringArrayListExtra("mCacheCheckImages");
		int position = getIntent().getIntExtra("position", 0);
		mPreviewViewPager = (ViewPager) findViewById(R.id.preview_pager);
		//getResources().getStringArray(R.array.light_images);
		mImages = getImages(list);
//		mDisplayImageOptions = AppContext.getInstance().getDisplayImageOptions();
		mPreviewPagerAdapter = new PreviewPagerAdapter(this, mImages);
		mPreviewViewPager.setAdapter(mPreviewPagerAdapter);
		mPreviewViewPager.setCurrentItem(position);
		mPreviewViewPager.setOnPageChangeListener(new MyOnPageChangeListener());
		updateView(list);
	}
	
	public void updateView(List<String> images){
		int curr = mPreviewViewPager.getCurrentItem();
		if (mTitleBar == null){
			mTitleBar = (TitleBar) findViewById(R.id.title_bar);
			mTitleBar.bindActivity(this);
		}
		if (list != null){
			mTitleBar.setUserName((curr+1) + "/" + list.size());
		}
	}
	
	private String [] getImages(List<String> list){
		if (list == null || list.isEmpty() || list.size() < 1) {
			return null;
		}
		String [] image = new String[list.size()];
		return list.toArray(image);
	}
	
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
	}

	private class MyOnPageChangeListener implements OnPageChangeListener{

		@Override
		public void onPageScrollStateChanged(int arg0) {
			updateView(list);
		}

		@Override
		public void onPageScrolled(int arg0, float arg1, int arg2) {
			
		}

		@Override
		public void onPageSelected(int arg0) {
			updateView(list);
		}
		
	}
	
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	}
	
}
